//
//  SafetyConfirmView.m
//  TenMinDemo
//
//  Created by Shawn Li on 2021/3/8.
//  Copyright © 2021 CYXiang. All rights reserved.
//

#import "SafetyConfirmView.h"
#import "VerifyCodeBtn.h"
#import "BaseTextField.h"
@interface SafetyConfirmView ()
@property (weak, nonatomic) IBOutlet UIView *bgView;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *phoneTop; // 102/5
@property (weak, nonatomic) IBOutlet UILabel *mailLabel;
@property (weak, nonatomic) IBOutlet UITextField *mailInput;
@property (weak, nonatomic) IBOutlet UILabel *mailSepLine;
@property (weak, nonatomic) IBOutlet UIButton *mailVerBtn;
@property (weak, nonatomic) IBOutlet VerifyCodeBtn *phoneVerBtn;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet BaseTextField *phoneInput;
@property (weak, nonatomic) IBOutlet BaseTextField *pswInput;

@property (weak, nonatomic) IBOutlet UILabel *pswLabel;


@end
@implementation SafetyConfirmView

INITFROMXIB
- (void)awakeFromNib{
    [super awakeFromNib];
    CGRect frame = self.bgView.bounds;
    frame.size.width = SCREEN_WIDTH;
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect: frame byRoundingCorners:UIRectCornerTopLeft | UIRectCornerTopRight cornerRadii:CGSizeMake(10,10)];
      //创建 layer
      CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
      maskLayer.frame = frame;
      //赋值
      maskLayer.path = maskPath.CGPath;
    self.bgView.layer.mask = maskLayer;
    LRWeakSelf(self);
    self.phoneVerBtn.clickBlock = ^{
        if (weakself.actionBlock) {
            weakself.actionBlock(2,@{});
        }
    };
    [self.phoneVerBtn configVerifyBtn:60];
    self.phoneInput.placeholder = LCLocalString(@"plh_qsryzm");
    self.phoneInput.placeholderColor = PlhColor;
    self.pswInput.placeholder = LCLocalString(@"fpsw_qsrymm");
    self.pswInput.placeholderColor = PlhColor;
    
}

- (void)refresh{
    self.phoneLabel.text = self.phoneNum;
    if ([self.confirmType isEqual:@"1"]) {
//        转出
        self.pswLabel.text = LCLocalString(@"psw_zjmm");
        self.pswInput.placeholder = LCLocalString(@"fpsw_qsrymm");
    }else{
//        修改资金密码
        self.pswLabel.text = LCLocalString(@"dlmm");
        self.pswInput.placeholder = LCLocalString(@"plh_qsrdlmm");
    }
}

- (void)showInView:(UIView *)view{
    [self refresh];
    [view addSubview:self];
    [self show];
}


- (void)show{
    self.backgroundColor = [UIColor clearColor];
    self.bgBottom.constant = -450;
    [UIView animateWithDuration:0.35 animations:^{
        self.backgroundColor = [[UIColor alloc] initWithWhite:0 alpha:0.8];
        self.bgBottom.constant = 0;
        [self layoutIfNeeded];
        } completion:^(BOOL finished) {
            
        }];
    
}

- (void)hide{
    [self endEditing:YES];
    [UIView animateWithDuration:0.35 animations:^{
       
        self.backgroundColor = [UIColor clearColor];
        self.bgBottom.constant = -450;
        [self layoutIfNeeded];
        } completion:^(BOOL finished) {
            [self removeFromSuperview];
        }];
    
}

- (IBAction)cancelAction:(id)sender {
    [self hide];
    if (self.actionBlock) {
        self.actionBlock(0,nil);
    }
}

- (IBAction)doneAction:(id)sender {
    if (!self.phoneInput.text.length) {
        LCInfoHUD(@"plh_qsryzm", 1);
        return;
    }
    if (!self.pswInput.text.length) {
        LCInfoHUD(@"fpsw_qsrymm", 1);
        return;
    }
    
    if (self.actionBlock) {
        self.actionBlock(1,@{@"verCode":self.phoneInput.text,@"pswCode":self.pswInput.text});
    }
    [self hide];
}

- (void)verBeginRun{
    [self.phoneVerBtn beginRun];
}

@end
